//
//  HJTitleCell.m
//  KaiChat
//
//  Created by lx on 2023/10/18.
//

#import "HJTitleCell.h"

 
@interface HJTitleCell()

@property (nonatomic, weak) UIView *lineView;
@property (nonatomic, weak) UIImageView *arrowImageView;
@property (nonatomic, weak) UILabel *titleLabel;
@property (nonatomic, weak) UILabel *detailTitleLabel;


@end


@implementation HJTitleCell



- (void)settingSubView {
 
    self.backgroundColor = UIColor.whiteColor;
    
    _titleLabel = [UILabel lableWithSuperView:self.contentView font:UIFontMake(14) color:UIColor.tj_333333Color title:nil textAlignment:NSTextAlignmentLeft];
    [_titleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.offset(leftRightMargin);
        make.centerY.offset(0);
    }];
    
    _arrowImageView = [UIImageView addToView:self.contentView];
    _arrowImageView.image = [UIImage imageNamed:@"cell_arrow"];
    [_arrowImageView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.inset(leftRightMargin);
        make.centerY.offset(0);
    }];
    
    _lineView = [UIView addToView:self.contentView];
    _lineView.backgroundColor = [UIColor.tj_CCCCCCColor colorWithAlphaComponent:0.2];
    [_lineView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.right.offset(0);
        make.bottom.offset(0);
        make.height.offset(lineHeight);
    }];
    
    _detailTitleLabel = [UILabel lableWithSuperView:self.contentView font:UIFontMake(14) color:UIColor.tj_333333Color title:nil textAlignment:NSTextAlignmentRight];
    [_detailTitleLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(_arrowImageView.mas_left).inset(3);
        make.centerY.offset(0);
        make.width.mas_lessThanOrEqualTo(200);
    }];

}

- (void)setModel:(HJCellModel *)model {
    _model = model;
    
    _titleLabel.text = model.text;
    _detailTitleLabel.text = model.detailText;
    _lineView.hidden = !model.showLine;
    
    if (model.showArrow) {
        _arrowImageView.hidden = NO;
        [_arrowImageView mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.inset(leftRightMargin);
            make.centerY.offset(0);
        }];
        
        [_detailTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.equalTo(_arrowImageView.mas_left).inset(5);
            make.centerY.offset(0);
            make.width.mas_lessThanOrEqualTo(200);
        }];
 
    } else {
        _arrowImageView.hidden = YES;
        [_arrowImageView mas_remakeConstraints:^(MASConstraintMaker *make) {}];
        
        [_detailTitleLabel mas_remakeConstraints:^(MASConstraintMaker *make) {
            make.right.inset(leftRightMargin);
            make.centerY.offset(0);
            make.width.mas_lessThanOrEqualTo(200);
        }];
    }
    
    [_lineView mas_updateConstraints:^(MASConstraintMaker *make) {
        make.left.inset(model.separatorInset.left);
        make.right.inset(model.separatorInset.right);
    }];
    
    _titleLabel.font = model.textFont ?: UIFontMake(14);
    _titleLabel.textColor = model.textColor ?: UIColor.tj_333333Color;

    _detailTitleLabel.font = model.detailTextFont ?: UIFontMake(14);
    _detailTitleLabel.textColor = model.detailTextColor ?: UIColor.tj_9D9D9DColor;
}
 

@end
